﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace SampleStockWP
{
    public partial class ChartVN : PhoneApplicationPage
    {
        String base_URL = "http://ichart.yahoo.com/";
        public ChartVN()
        {
            InitializeComponent();
        }

        private void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            pbarWebClient.Visibility = System.Windows.Visibility.Collapsed;
            webBrowser1.Opacity = 1.0;
        } 

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (NavigationContext.QueryString["opt"] == "1" && NavigationContext.QueryString["sym"].Length > 0)
            {
                string sym = NavigationContext.QueryString["sym"].ToLower() + ".png";
                webBrowser1.Navigate(new Uri("http://www.cophieu68.com/imagechart/line/" + sym, UriKind.Absolute));
            }
            else if (NavigationContext.QueryString["opt"] == "2" && NavigationContext.QueryString["sym"].Length > 0)
            {
                string sym = NavigationContext.QueryString["sym"].ToLower();
                string url = "http://ichart.yahoo.com/z?s=" + sym + "&t=6m&q=l&l=on&z=l&p=m50,e200";
                webBrowser1.Navigate(new Uri(url, UriKind.Absolute));
            }
            else if (NavigationContext.QueryString["opt"] == "3" && NavigationContext.QueryString["sym"].Length > 0)
            {
                string sym = NavigationContext.QueryString["sym"];
                string size = NavigationContext.QueryString["size"];
                string time = NavigationContext.QueryString["time"];
                string type = NavigationContext.QueryString["type"];
                string scale = NavigationContext.QueryString["scale"];
                string ma = NavigationContext.QueryString["ma"];
                string ema = NavigationContext.QueryString["ema"];
                string IDs = NavigationContext.QueryString["ids"];

                String url = base_URL;
                url += size;
                url += "?s=" + sym;
                url += "&t=" + time;
                url += "&q=" + type;
                url += "&l=" + scale;
                url += "&p=" + ma + "," + ema;
                if (IDs.Length != 0)
                    url += "&c=" + IDs;
                webBrowser1.Navigate(new Uri(url, UriKind.Absolute));
            }
        }
    }
}